import{Mongoose,Schema,Model,Document} from 'mongoose';
import { BaseDao} from './BaseDao';
import {Project} from '../models/Project';
export class ProjectsDao extends BaseDao
{
  projectModel:Model<any>;
  constructor(){
    super();
    this.projectModel = this.dbManager.getModel("mProject");
  }
  add(project:Project,callback:Function)
  {
    var project_ = new this.projectModel(project);
    project_.save(callback);
  }
  get(projectId:string,callback:Function)
  {
    this.projectModel.findOne({_id:projectId}).exec(callback);
  }

  gets(callback:Function)
  {
    this.projectModel.find().exec(callback);
  }
  
  getMines(userId:string,callback:Function)
  {
    this.projectModel.find({user:userId}).exec(callback);
  }

  update(project:Project,callback:Function)
  {
    var query = {_id:project._id};
    var updater = {
      title : project.title,
      description:project.description,
      open:project.open
    }
    this.projectModel.update(query,updater).exec(callback);
  }

  delete(projectId:string,callback:Function)
  {
    this.projectModel.remove({_id:projectId}).exec(callback);
  }

}
